package practice;

import java.util.List;

/**
 * @author ：wangchao
 * @version ：V1.0
 * @program ：MySpringCloud
 * @date ：Created in 2020/10/12 10:43
 * @description ：树转数组
 */
public class TreeConvertArray {
    class Treenode {
        int value;
        Treenode left;
        Treenode right;

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        public Treenode getLeft() {
            return left;
        }

        public void setLeft(Treenode left) {
            this.left = left;
        }
        public Treenode getRight() {
            return right;
        }
        public void setRight(Treenode right) {
            this.right = right;
        }
    }
    public void createArrayByTree(List<Integer> list, Treenode root, int index) {
        if (root == null) {
            return;
        }
        int[] arr = new int[10];
        arr[index] = 10;
        list.add(index, root.getValue());
        if (root.getLeft() != null) {
            createArrayByTree(list, root.getLeft(), 2 * index + 1);
        }
        if (root.getRight() != null) {
            createArrayByTree(list, root.getRight(), 2 * index + 2);
        }
    }
}